package lgkj.meicqt20.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import lgkj.meicqt20.R;
import lgkj.meicqt20.bean.EliteEnity;
import lgkj.meicqt20.utils.CommUtils;

/**
 * Created by Administrator on 2017/8/21 0021.
 */

public class EliteAdapter extends BaseAdapter {
    private List<EliteEnity.DataBean> eliteEnity;
    private Context context;

    private int postion = -1;

    public void setData(List<EliteEnity.DataBean> data) {
        if (data != null) {
            this.eliteEnity = data;
        }
    }

    public void setPostion(int postion) {
        this.postion = postion;
    }

    public EliteAdapter(Context context) {
        this.context = context;
        eliteEnity = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return eliteEnity.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder = null;
        if (view == null) {
            holder = new Holder();
            view = LayoutInflater.from(context).inflate(R.layout.item_elite, null);
            holder.ll_item = (LinearLayout) view.findViewById(R.id.ll_item);
            holder.iv_photo = (ImageView) view.findViewById(R.id.iv_photo);
            holder.tv_name = (TextView) view.findViewById(R.id.tv_name);
            holder.tv_desc = (TextView) view.findViewById(R.id.tv_desc);
            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        if (i == postion) {
            holder.ll_item.setBackgroundResource(R.mipmap.edit_item_che);
        } else {
            holder.ll_item.setBackgroundResource(0);
        }
        holder.tv_name.setText(eliteEnity.get(i).getBarber_name());
        holder.tv_desc.setText("\n" + eliteEnity.get(i).getBarber_text());
        CommUtils.LoadImage(context, holder.iv_photo, eliteEnity.get(i).getBaber_img_url(), R.drawable.common_icon_err);
        return view;
    }

    class Holder {
        LinearLayout ll_item;
        TextView tv_name, tv_desc;
        ImageView iv_photo;
    }
}
